package com.team233.zuccecho.repository;

import com.team233.zuccecho.Bean.Feedback;
import com.team233.zuccecho.Bean.Question;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.persistence.criteria.CriteriaBuilder;
import javax.transaction.Transactional;
import java.util.List;

public interface QuestionRepository extends JpaRepository<Question,Long> {
    @Query(value="select * from question where question_id=?1",nativeQuery = true)
    Question findQuesById(long question_id);

    //获取某问卷的所有问题
    @Query(value = "select * FROM question\n" +
            "WHERE question_id IN\n" +
            "(SELECT question_id FROM questionnaire_question\n" +
            "WHERE questionnaire_id =?1\n" +
            ")",nativeQuery = true)
    List<Question> getQnqs(long questionnaire_id);

    //获取模板所有问题
    @Query(value = "select * \n" +
            "from question \n" +
            "where question_id in \n" +
            "(select question_id \n" +
            "from template_question \n" +
            "where template_id =5)",nativeQuery = true)
    List<Question> getTemQs(long tem_id);

    @Transactional
    @Query(value = "DELETE\n" +
            "from template_question\n" +
            "where template_id =?1",nativeQuery = true)
    @Modifying
    void removeTemQsById(long template_id);
}
